package cn.kimming.wms.query;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import cn.kimming.wms.domain.OrderBill;
import cn.kimming.wms.util.DateUtils;
import lombok.Getter;
import lombok.Setter;

//订货报表高级查询对象, 查询主体:OrderBillItem
public class OrderChartQueryObject extends QueryObject {
	@Getter @Setter
	private Date beginDate;
	@Getter @Setter
	private Date endDate;
	@Getter @Setter
	private String keyword; // 关键字:货品名称或关键字
	@Getter @Setter
	private Long supplierId = -1L; // 供应商
	@Getter @Setter
	private Long brandId = -1L; // 所属品牌
	@Getter @Setter
	private String orderGroupType = "EMPLOYEE";

	protected void customizedQuery() {
		if (beginDate != null) {
			addCondition("obj.bill.vdate >= ?", DateUtils.getBeginDate(beginDate));
		}
		if (endDate != null) {
			addCondition("obj.bill.vdate <= ?", DateUtils.getEndDate(endDate));
		}
		if (StringUtils.isNotEmpty(keyword)) {
			addCondition("(obj.product.name like ? or obj.product.sn like ?)", "%" + keyword + "%", "%" + keyword + "%");
		}
		if (supplierId > 0) {
			addCondition("obj.bill.supplier.id = ?", supplierId);
		}
		if (brandId > 0) {
			addCondition("obj.product.brand.id = ?", brandId);
		}
		//只查询已审核的
		addCondition("obj.bill.status = ?", OrderBill.AUDIT);
	};
}
